<?php defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH.'/libraries/REST_Controller.php';

class address extends REST_Controller
{     
	function get_street_by_id_get()
	{
		if(!$this->get('street_id')) {
			$this->response(array('status'=>"false",
					'message' => 'street_id not provided'), 200);
		}
		$this->load->model('addressdao');
		$success = $this->addressdao->get_street_by_id($this->get('street_id'));
		$this->response(array('street'=>$success,'status'=> $success ? 'true' : 'false'), 200);
	}

	function get_streets_get()
	{
		$this->load->model('addressdao');
		$success = $this->addressdao->get_all_streets();
		$this->response(array('streets'=>$success,'status'=> $success ? 'true' : 'false'), 200);
	}
	
	function get_district_by_id_get()
	{
		if(!$this->get('disctrict_id'))
		{
			$this->response(NULL, 400);
		}
		$this->load->model('addressdao');
		$district = $this->addressdao->get_district_by_id($this->get('district_id'));
		$this->response(array('district'=>$district,'status'=> $district ? 'true' : 'false'), 200);
	}
	
	function get_districts_get()
	{
		$this->load->model('addressdao');
		$districts = $this->addressdao->get_all_districts();
		$this->response(array('districts'=>$districts,'status'=> $district ? 'true' : 'false'), 200);
	}
	
	function get_city_by_id_get()
	{
		if(!$this->get('city_name'))
		{
			$this->response(NULL, 400);
		}
		$this->load->model('addressdao');
		$city = $this->addressdao->get_city_by_name($this->get('city_name'));
		$this->response(array('city'=>$city,'status'=> $city ? 'true' : 'false'), 200);
	}
	
	function get_all_cities_get()
	{
		$this->load->model('addressdao');
		$city = $this->addressdao->get_all_cities();
		$this->response(array('city'=>$city,'status'=> $city ? 'true' : 'false'), 200);
	}
	
	function get_neighborhood_by_id_get()
	{
		if(!$this->get('neighborhood_id'))
		{
			$this->response(NULL, 400);
		}
		$this->load->model('addressdao');
		$neighborhood = $this->addressdao->get_neighborhood_by_name_get($this->get('neighborhood_id'));
		$this->response(array('city'=>$neighborhood,'status'=> $neighborhood ? 'true' : 'false')
				, 200);
	}
	
	function get_neighborhoods_get()
	{
		$this->load->model('addressdao');
		$neighborhoods = $this->addressdao->get_all_neighborhoods();
		$this->response(array('city'=>$neighborhoods,'status'=> $neighborhoods ? 'true' : 'false'), 200);
	}
	
}
?>